package com.tencent50.easy;

/**
 * @author: zhengtao
 * @description:   反转字符串中的单词 III
 * @version: 1.0
 * @date: 2022/07/25  22:57
 */
public class Demo23 {
    public String reverseWords(String s) {
        String[] s1 = s.split(" ");
        for (int i = 0; i < s1.length; i++) {
            s1[i]=reverseWord(s1[i]);
        }
        String newString="";
        for (int i = 0; i < s1.length; i++) {
            newString+=s1[i];
            if(i!=s1.length-1){
                newString=newString+" ";
            }
        }
        return newString;
    }

    private String reverseWord(String s) {

        int end=s.length()-1;
        String newS="";
        for (int i = end; i >= 0; i--) {
            newS+=s.charAt(i);
        }
        return newS;
    }
}
